package com.mty.springboot.service.impl;

import com.mty.springboot.dao.LossDao;
import com.mty.springboot.model.Loss;
import com.mty.springboot.model.PageInfo;
import com.mty.springboot.service.LossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.mty.springboot.util.uuid;

/**
 * 用户Service接口实现类
 * @author: mty
 */
@Service("lossService")
@Transactional
public class LossServiceImpl implements LossService {

    @Autowired
    private LossDao lossDao;


    //分页查询
    @Override
    public PageInfo<Loss> findPageInfo(Integer pageIndex, Integer pageSize,Map mp) {
        PageInfo<Loss> pi = new PageInfo<Loss>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        int currentPage = (pi.getPageIndex()-1)*pi.getPageSize();
        mp.put("currentPage",currentPage);
        mp.put("pageSize",pi.getPageSize());
        //获取总条数
        Integer totalCount = lossDao.totalCount(mp);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //按条件查询
            List<Loss> lossList =	lossDao.getLossList(mp);
            pi.setList(lossList);
        }
        return pi;
    }


    //添加
    @Override
    public int addLoss(Loss loss) {
        loss.setId(uuid.getRandomIdByUUID());
        return lossDao.addLoss(loss);
    }


    //根据id删除
    @Override
    public int deleteLoss(String id) {
        return lossDao.deleteLoss(id);
    }


    //修改信息
    @Override
    public int updateLoss(Loss loss) {
        return lossDao.updateLoss(loss);
    }

    //根据ID查询
    @Override
    public Loss findLossById (String id){
        Loss d = lossDao.findLossById(id);
        return  d;
    }

    //查询所有
    @Override
    public List<Loss> getAll(){
        List<Loss> lossList = lossDao.getAll();
        return lossList;
    }

    //按照条件查询
    @Override
    public List<Loss> queryFilter(Map mp){
        List<Loss> lossList = lossDao.queryFilter(mp);
        return lossList;
    }
}
